package com.shu.component_base.ui.activity;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * Activity管理类
 * @author yangshu
 * createDate 20.7.23
 */
public class ActivityCollector {
    private static List<Activity> sActivities = new ArrayList<>();

    /**
     * 添加处于已经创建完成的的activity
     * @param activity
     */
    public static void addActivity(Activity activity) {
        sActivities.add(activity);
    }

    /**
     * 移除activity
     * @param activity
     */
    public static void removeActivity(Activity activity) {
        sActivities.remove(activity);
    }

    /**
     * 结束所有activity
     */
    public static void finishAll() {
        for (Activity activity : sActivities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
        sActivities.clear();
    }
}
